﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SP_BuocGiaCong.ascx.cs" Inherits="uicontrol_SP_BuocGiaCong" %>
<asp:SqlDataSource ID="dsTB" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>"
    DataSourceMode="DataReader" ProviderName="<%$ ConnectionStrings:evaConn.ProviderName %>"
    SelectCommand="SELECT MaThietBi, TenThietBi FROM ThietBi WHERE (Status = 1) AND (MaDoanhNghiep = @MaDoanhNghiep)">
    <SelectParameters>
        <asp:SessionParameter DefaultValue="0" Name="MaDoanhNghiep" SessionField="CompanyID" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsBGCEdit" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>" ProviderName="<%$ ConnectionStrings:evaConn.ProviderName %>"
    SelectCommand="SELECT BuocGiaCong.TenBuocGiaCong, HoiDong.TenHoiDong, SanPham.TenSanPham, BuocGiaCong.GhiChu, ThietBi.TenThietBi, ThietBi.MaThietBi, BuocGiaCong.MaBuocGiaCong FROM BuocGiaCong INNER JOIN SanPham ON BuocGiaCong.MaSanPham = SanPham.MaSanPham INNER JOIN HoiDong ON BuocGiaCong.MaHoiDong = HoiDong.MaHoiDong AND SanPham.MaHoiDong = HoiDong.MaHoiDong AND SanPham.MaHoiDong = HoiDong.MaHoiDong INNER JOIN ThietBi ON BuocGiaCong.MaThietBi = ThietBi.MaThietBi WHERE (BuocGiaCong.MaBuocGiaCong = @MaBuocGiaCong)" UpdateCommand="UPDATE BuocGiaCong SET TenBuocGiaCong = @TenBuocGiaCong, GhiChu = @GhiChu, MaThietBi = @MaThietBi WHERE (MaBuocGiaCong = @MaBuocGiaCong)">
    <UpdateParameters>
        <asp:ControlParameter ControlID="txtTenBGC" Name="TenBuocGiaCong" PropertyName="Text" />
        <asp:ControlParameter ControlID="txtDescr" Name="GhiChu" PropertyName="Text" />
        <asp:ControlParameter ControlID="ddlTB" Name="MaThietBi" PropertyName="SelectedValue" />
        <asp:SessionParameter Name="MaBuocGiaCong" SessionField="MaBuocGiaCong" />
    </UpdateParameters>
    <SelectParameters>
        <asp:SessionParameter Name="MaBuocGiaCong" SessionField="MaBuocGiaCong" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsSP" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>" ProviderName="<%$ ConnectionStrings:evaConn.ProviderName %>"
    SelectCommand="SELECT SanPham.MaSanPham, SanPham.TenSanPham, SanPham.MaHoiDong, SanPham.Status, HoiDong.TenHoiDong, SanPham.MaDoanhNghiep FROM SanPham INNER JOIN HoiDong ON SanPham.MaHoiDong = HoiDong.MaHoiDong AND SanPham.MaHoiDong = HoiDong.MaHoiDong WHERE (SanPham.Status = 1) AND (HoiDong.Status = 1) AND (SanPham.MaDoanhNghiep = @MaDoanhNghiep) AND (SanPham.MaSanPham = @MaSanPham)">
    <SelectParameters>
        <asp:SessionParameter DefaultValue="0" Name="MaDoanhNghiep" SessionField="CompanyID" />
        <asp:SessionParameter DefaultValue="0" Name="MaSanPham" SessionField="spID" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsBGC" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>" ProviderName="<%$ ConnectionStrings:evaConn.ProviderName %>"
    SelectCommand="SELECT BuocGiaCong.MaBuocGiaCong, BuocGiaCong.TenBuocGiaCong, BuocGiaCong.MaSanPham, BuocGiaCong.MaHoiDong, BuocGiaCong.MaThietBi, ThietBi.TenThietBi, BuocGiaCong.GhiChu FROM BuocGiaCong INNER JOIN ThietBi ON BuocGiaCong.MaThietBi = ThietBi.MaThietBi WHERE (BuocGiaCong.Status = 1) AND (BuocGiaCong.MaSanPham = @MaSanPham)" 
    InsertCommand="INSERT INTO BuocGiaCong(TenBuocGiaCong, MaSanPham, MaHoiDong, GhiChu, MaThietBi) VALUES (@TenBuocGiaCong, @MaSanPham, @MaHoiDong, @GhiChu, @MaThietBi)" 
    UpdateCommand="UPDATE BuocGiaCong SET Status = 0 WHERE (MaBuocGiaCong = @MaBuocGiaCong)">
    <SelectParameters>
        <asp:SessionParameter DefaultValue="0" Name="MaSanPham" SessionField="spID" />
    </SelectParameters>
    <InsertParameters>
        <asp:ControlParameter ControlID="txtTenBGC" DefaultValue=" " Name="TenBuocGiaCong" PropertyName="Text" />
        <asp:SessionParameter DefaultValue="0" Name="MaSanPham" SessionField="spID" />
        <asp:SessionParameter DefaultValue="0" Name="MaHoiDong" SessionField="MaHoiDong"/>
        <asp:ControlParameter ControlID="txtDescr" DefaultValue=" " Name="GhiChu" PropertyName="Text" />
        <asp:ControlParameter ControlID="ddlTB" DefaultValue="0" Name="MaThietBi" PropertyName="SelectedValue" />
    </InsertParameters>    
</asp:SqlDataSource>
<table style="width:600px">
    <tr>
        <td colspan="2">
            <asp:Label ID="Label4" runat="server" CssClass="LabelTitle" Text="BƯỚC GIA CÔNG"></asp:Label></td>
        <td>
        </td>
    </tr>
    <tr>
        <td style="width: 30%">
        </td>
        <td>
            &nbsp;</td>
        <td>
        </td>
    </tr>
    <tr>
        <td style="width: 30%">
            <asp:Label ID="Label1" runat="server" CssClass="Label" Text="Tên Bước gia công"></asp:Label></td>
        <td>
            <asp:TextBox ID="txtTenBGC" runat="server" CssClass="Textbox" MaxLength="100" TabIndex="1"></asp:TextBox></td>
        <td>
            <asp:RequiredFieldValidator ID="rfvTenSP" runat="server" ControlToValidate="txtTenBGC"
                CssClass="ValidateLabel" ErrorMessage="Không được trống"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label2" runat="server" CssClass="Label" Text="Tên Sản phẩm"></asp:Label></td>
        <td>
            <asp:Label ID="lblTenSP" runat="server" CssClass="Label"></asp:Label></td>
        <td>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label3" runat="server" CssClass="Label" Text="Hội đồng"></asp:Label></td>
        <td>
            <asp:Label ID="lblHD" runat="server" CssClass="Label"></asp:Label></td>
        <td>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label5" runat="server" CssClass="Label" Text="Thiết bị"></asp:Label></td>
        <td>
            <asp:DropDownList ID="ddlTB" runat="server" DataSourceID="dsTB" DataTextField="TenThietBi" DataValueField="MaThietBi" TabIndex="2" CssClass="DropdownList">
            </asp:DropDownList></td>
        <td>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label6" runat="server" CssClass="Label" Text="Ghi chú"></asp:Label></td>
        <td>
            <asp:TextBox ID="txtDescr" runat="server" CssClass="TextArea" MaxLength="1000" TabIndex="3" Height="45px" Rows="3" TextMode="MultiLine"></asp:TextBox></td>
        <td>
        </td>
    </tr>
    <tr>
        <td colspan="2" style="text-align: center">
            <asp:Button ID="btnNew" runat="server" CssClass="Button" TabIndex="4" Text="Tạo mới" OnClick="btnNew_Click" />&nbsp;
            <asp:Button ID="btnUpdate" runat="server" CssClass="Button" TabIndex="4" Text="Cập nhật" OnClick="btnUpdate_Click" Visible="False" />&nbsp;
            <asp:Button ID="btnCancel" runat="server" CausesValidation="False" CssClass="Button"
                TabIndex="5" Text="Làm lại" OnClick="btnCancel_Click" /></td>
        <td>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            &nbsp;<asp:Label ID="lblResult" runat="server" CssClass="LabelResult"></asp:Label></td>
        <td>
        </td>
    </tr>
</table>
<table>
    <tr><td>
        <asp:Label ID="Label7" runat="server" CssClass="LabelResult" Text="Sản phẩm này có các bước gia công là :"></asp:Label></td></tr>
    <tr><td>
        <asp:GridView ID="grvBGC" DataKeyNames="MaBuocGiaCong" runat="server" AllowPaging="True" DataSourceID="dsBGC" PageSize="5" AutoGenerateColumns="False" OnRowDataBound="grvBGC_RowDataBound" CssClass="Grv" OnSelectedIndexChanging="grvBGC_SelectedIndexChanging" OnRowCommand="grvBGC_RowCommand">
            <Columns>
                <asp:BoundField DataField="MaBuocGiaCong" HeaderText="MaBuocGiaCong" />
                <asp:BoundField DataField="TenBuocGiaCong" HeaderText="Bước Gia c&#244;ng" >
                    <HeaderStyle Width="30%" />
                </asp:BoundField>
                <asp:BoundField DataField="MaSanPham" HeaderText="MaSanPham" />
                <asp:BoundField DataField="MaHoiDong" HeaderText="MaHoiDong" />
                <asp:BoundField DataField="MaThietBi" HeaderText="MaThietBi" />
                <asp:BoundField DataField="TenThietBi" HeaderText="Thiết bị" >
                    <HeaderStyle Width="26%" />
                </asp:BoundField>
                <asp:BoundField DataField="GhiChu" HeaderText="Ghi ch&#250;" >
                    <HeaderStyle Width="30%" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="Chức năng">
                    <ItemTemplate>
                        <asp:ImageButton ID="sua" CommandArgument='<%# Eval("MaBuocGiaCong") %>' CommandName="Sua" runat="server" ImageUrl="~/App_Themes/Default/Css/images/edit.gif" CausesValidation="false"/>
                        <asp:ImageButton ID="xoa" CommandArgument='<%# Eval("MaBuocGiaCong") %>' CommandName="Xoa" runat="server" ImageUrl="~/App_Themes/Default/Css/images/delete.gif" CausesValidation="false"/>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" />
                </asp:TemplateField>                
            </Columns>
            <PagerStyle CssClass="GrvPagerStyle"/>
                <HeaderStyle CssClass="GrvHeader" />
                <RowStyle CssClass="GrvRowStyle"/>
                <AlternatingRowStyle CssClass="GrvAlternatingRowStyle" />  
</asp:GridView>
    </td></tr>
</table>

